# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Baptiste Jonglez <baptiste--aur at jonglez dot org>

pkgname=jami-daemon
pkgver=20230922
pkgrel=1
pkgdesc="Free and universal communication platform which preserves the users’ privacy and freedoms (daemon component)"
arch=(loong64 x86_64)
url="https://jami.net"
license=(GPL3)
groups=(jami)
depends=(glibc opendht gnutls nettle libgit2 libsecp256k1 libsecp256k1.so ffmpeg speexdsp
         fmt yaml-cpp jsoncpp zlib alsa-lib libpulse jack libupnp libnatpmp
         openssl webrtc-audio-processing systemd-libs libarchive)
# portaudio needs a not-yet-upstream patch https://git.jami.net/savoirfairelinux/jami-daemon/-/issues/650
makedepends=(git cmake perl asio msgpack-c msgpack-cxx restinio systemd meson)
checkdepends=(cppunit)
_commit=3bbac8728399d1d89eb21cae8eed2a465b1aecb3
_pjprojectver=97f45c2040c2b0cf6f3349a365b0e900a2267333
_dhtnetver=2f3539bc19cf770cd23912c7eebe63e8d2f80515
source=(git+https://git.jami.net/savoirfairelinux/${pkgname}.git#commit=${_commit}
        https://github.com/savoirfairelinux/pjproject/archive/${_pjprojectver}/pjproject-${_pjprojectver}.tar.gz
        dhtnet-$_dhtnetver.tar.gz::https://review.jami.net/plugins/gitiles/dhtnet/+archive/$_dhtnetver.tar.gz)
noextract=(pjproject-${_pjprojectver}.tar.gz
           dhtnet-${_dhtnetver}.tar.gz)
sha512sums=('SKIP'
            'b9fa03bb2586262849859f025c9b0d7742a7da8a528c4c09b75e6fcc448d82fe90e9fe79aba2efe9c3485c079222b0b0fbd5c8f5d55c842b869e97297993f58c'
            'SKIP')

pkgver() {
  cd ${pkgname}
  TZ=UTC git show -s --pretty=%cd --date=format-local:%Y%m%d HEAD
}

prepare() {
  cd ${pkgname}
  cp ../pjproject-${_pjprojectver}.tar.gz contrib/tarballs
  cp ../dhtnet-$_dhtnetver.tar.gz contrib/tarballs/
  mkdir contrib/native
}

build() {
  cd ${pkgname}/contrib/native
  ../bootstrap \
      --disable-downloads \
      --disable-all \
      --enable-pjproject \
      --enable-dhtnet
  make DEPS_pjproject= DEPS_dhtnet=pjproject

  cd "${srcdir}"
  arch-meson ${pkgname} build -D interfaces=library -D opensl=disabled -D portaudio=disabled \
                              $( ((CHECKFUNC)) && echo -D tests=true) \
                              -D pkg_config_path="${PWD}/${pkgname}/contrib/$(cc -dumpmachine)/lib/pkgconfig"
  meson compile -C build
}

#check() {
# https://git.jami.net/savoirfairelinux/jami-daemon/-/issues/649
#  meson test -C build --print-errorlogs
#}

package() {
  meson install -C build --destdir "${pkgdir}"
}
